FROM ubuntu:20.04

WORKDIR /app

# 设置环境变量避免交互式提示
ENV DEBIAN_FRONTEND=noninteractive

# 使用国内镜像源
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list

# 安装 Python 和依赖
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    python3.8 \
    python3-pip \
    python3.8-dev \
    python3-setuptools \
    python3-wheel \
    gcc \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# 创建 Python 软链接
RUN ln -sf /usr/bin/python3.8 /usr/bin/python && \
    ln -sf /usr/bin/pip3 /usr/bin/pip

# 设置 pip 镜像源
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

# 复制依赖文件
COPY requirements-base.txt .

# 安装 Python 依赖
RUN pip install --no-cache-dir -r requirements-base.txt

# 复制源代码
COPY src/ ./src/

# 设置环境变量
ENV PYTHONPATH=/app
ENV HOST=0.0.0.0
ENV PORT=8080
ENV PYTHONUNBUFFERED=1

# 暴露端口
EXPOSE 8080

# 清除代理设置
ENV http_proxy=""
ENV https_proxy=""

# 启动命令
CMD ["python", "src/main_base.py"]
